Skip to content

fix(codex): resume account switches without blanking the terminal - #25485

Merged
nwparker merged 1 commit into
mainfrom
nwparker/codex-restart-account
Oct 5, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/codex-restart-account

Conversation

@nwparker

@nwparker nwparker commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1324 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1304
Prod 19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​428 $\color{#cf222e}{\Huge{\mathbf{−}}}$​75 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​353

ELI5

After switching Codex accounts, Restart could leave an unusable blank terminal or reopen the previous account and ask to restart again. It now replaces the stopped process and resumes the same conversation using the selected account.

What Changed

  • Adopt fix(terminal): restart a Codex pane into a fresh process after an account switch #24350's atomic pane replacement: hold the pane reservation across shutdown, exclude only the process just stopped, and swap its saved binding when the new process is admitted. A newer owner wins; failed replacements clear only the stopped binding.
  • Adapt fix(codex): land an account-switch restart on the newly selected account #14877's explicit conversation resume for mounted and hidden panes. A replacement follows the selected account and safely installs the verified rollout there; ordinary restores still use the original account. The existing replacement ID carries intent, so no new IPC field is needed.
  • Allow terminal protocol replies while an account notice blocks typing. Codex can complete its terminal handshake instead of waiting behind its own restart notice.

Why

The daemon correctly rejects attachment to a killed process. Changing general liveness classification hid the stale binding rather than fixing its replacement. #24350's narrower ownership transaction handles concurrent spawns, split panes, and direct SSH. The explicit resume from #14877 prevents stale recovery state from choosing the account or another agent's session.

Credit: @brennanb2025 (Brennan Benson) for #24350, @itisvincent for its credited predecessor #18190, and @tonite31 (Rayim) for #14877's account-selection diagnosis and resume builder. Their contributions are credited in the commit trailers, including #14877's original AI coauthor.

Linked Issue

Related: #20142, #19589. Integrates the replacement fix from #24350 and the conversation/account portions of #14877. This does not supersede all of #14877: its goal-state transfer and account-settings copy changes are outside this patch.

Visual Proof

Before, reproduced blank pane after Restart:

Blank terminal after the original restart

After, same conversation resumed on account B and completed a second prompt:

Conversation and new response after switching accounts

Testing

  • Manually tested locally on macOS using an isolated, hidden Electron app and real Codex 0.160.0. Clicked the actual Restart dialog for A→B and B→A. Verified the transcript renders, a new prompt completes with the same session ID in B's home, Ctrl+C clears input, and no stale-account notices remain. First replacement PTY appeared in 2.7 seconds.
  • Automated regressions cover killed-owner replacement, concurrent successors, save/spawn failures, split panes, SSH partitions, selected-account rollout preparation, ordinary restore provenance, wrong-agent recovery, hidden restarts, and terminal query replies.
  • pnpm tc, changed-code quality checks, and pre-commit lint pass; 165 focused tests pass across 15 files after rebasing. Electron development build passed. GitHub Actions remained queued across the repository at merge time; there were no required status checks. Remote CI is pending, not claimed green.

AI Disclosure

Review

Self-reviewed using the repository-review workflow: ownership fencing, failure cleanup, rollout path validation/no-overwrite behavior, ordinary restores, and local/remote execution boundaries.

Agent skill upstream boundary

  • Not applicable; no skill source or registry changes.

Notes

Reliability invariant (agent-session.provider-ownership): an acknowledged replacement must never reattach the process it stopped, overwrite a successor, or resume the old account merely because it owns the transcript. Oracle: a fresh bound process with the same conversation and selected account; failure tests require successor preservation and recoverable remount. Focused tests are the experimental evidence for this change; no manifest promotion is claimed.

Coverage: local/daemon macOS rendered; split panes, direct SSH ownership and paired-runtime behavior tested with deterministic fixtures. Live Linux, Windows, WSL, SSH, and mobile are untested. WSL retains its existing fresh-relaunch fallback; paired-runtime restarts retain their existing host-owned behavior. No wire protocol changes. Folder paths remain supported. There is no new polling or process inventory scan; rollout preparation targets one verified file. Failure diagnostics use existing spawn errors plus a stopped-binding cleanup warning.

Residual gap: cross-account /goal state transfer is not included or claimed. The conversation rollout is preserved, but Codex also owns goal state in a separate database. Source inspection used the local ~/projects/codex checkout.

Checklist

  • Focused on account restart; most added lines are regression coverage from the upstream fix
  • Explained behavior, mechanism, and approach
  • Before/after screenshots attached
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path impact considered; live-test gaps stated
  • Local focused tests, typecheck, changed-code quality, and development build run; full checks delegated to CI

…e pane

Integrate the atomic pane replacement from #24350 and adapt the explicit
conversation resume from #14877. Keep terminal protocol replies flowing
while account notices block user input. Ordinary restores retain provenance.

Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
Co-authored-by: itisvincent <vincentcgamer@gmail.com>
Co-authored-by: rayim <rayim@fxy.global>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 9 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 55850958-f018-4d84-a448-2fd0bad03901
📥 Commits

Reviewing files that changed from the base of the PR and between c2c7649 and 6774c93.

📒 Files selected for processing (26)
  • src/main/codex/codex-legacy-session-resume.ts
  • src/main/ipc/pty-pane-restart-replace.test.ts
  • src/main/ipc/pty/host-env/codex-resume.ts
  • src/main/ipc/pty/host-env/types.ts
  • src/main/ipc/pty/ipc/spawn-begin.ts
  • src/main/ipc/pty/ipc/spawn-commit-persist.ts
  • src/main/ipc/pty/ipc/spawn-env-codex.ts
  • src/main/ipc/pty/ipc/spawn-execute.ts
  • src/main/ipc/pty/ipc/spawn-run.ts
  • src/main/ipc/pty/ipc/spawn-state.ts
  • src/main/ipc/pty/ipc/spawn-types.ts
  • src/main/ipc/pty/pane/pane-owner-replacement.test.ts
  • src/main/ipc/pty/pane/pane-owner-replacement.ts
  • src/main/persistence/loading-store/pty-binding-persistence.ts
  • src/main/persistence/loading-store/pty-binding-restart-retirement.test.ts
  • src/main/persistence/loading-store/replaced-pane-binding.ts
  • src/main/startup/codex-account-restart-resume.test.ts
  • src/main/startup/codex-session-resume-launch.ts
  • src/renderer/src/components/terminal-pane/codex-detached-pane-restart.ts
  • src/renderer/src/components/terminal-pane/pty-connection-reattach-mode-reset.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-process-exit-actions.ts
  • src/renderer/src/lib/codex-account-restart-startup.test.ts
  • src/renderer/src/lib/codex-account-restart-startup.ts
  • tests/e2e/terminal-account-restart.unit.test.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit 40f9e7a into main Oct 5, 2026
3 of 4 checks passed
Jinwoo-H added a commit that referenced this pull request Oct 19, 2026
…ad of Codex (#30872)

* fix(terminal): Restart on a failed terminal opens a plain shell instead of Codex

The exit card's Restart passed a null startup, and a Codex account-restart
fallback added in #25485 turned that null into `codex`. Account switches
already name their agent explicitly, so the fallback had no legitimate caller.

* test(terminal): stub the exit-actions controller without Reflect.get

---------

Co-authored-by: E2E Test <e2e@test.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant